package srt;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Database{
//String url="jdbc:mysql://localhost/liuyan?useUnicode=true&characterEncoding=utf-8";
String url = "jdbc:mysql://127.0.0.1:3306/HomeWorkDB";
String username="root";
String password="password";
Connection con=null;
Statement stmt;
ResultSet rs;
public Database(){
	stmt=null;
	rs=null;
	try{
	Class.forName("com.mysql.jdbc.Driver");
	}catch(ClassNotFoundException e){
	System.out.println("驱动异常");
	}try{
	con=DriverManager.getConnection(url,username,password);
	}catch(SQLException e){
	System.out.println("SQLexcepn就是这里");
	}
	if(con!=null){
	System.out.println("连接成功");
	}
}
public boolean exeSql(String strSql){
	try{
	stmt=con.createStatement();
	stmt.executeUpdate(strSql);
	return true;
	
	}catch(Exception ex){
	System.out.println(ex.toString());
	return false;
	}
}
public ResultSet exeSqlQuery(String strSql){
	try{
	stmt=con.createStatement();
	rs=stmt.executeQuery(strSql);
	}catch(Exception ex){
	System.out.println("获取结果集异常");
	System.out.println(ex.toString());
	return null;
	}
	return rs;
	}
}